    package edu.hubu.helloworld.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;


import java.util.List;

import edu.hubu.helloworld.R;
import edu.hubu.helloworld.entity.Friend;

public class FriendAdapter extends RecyclerView.Adapter<FriendAdapter.FriendViewHolder> {
    List<Friend> friendList;

    public FriendAdapter(List<Friend> friendList) {
        this.friendList = friendList;
    }

    static public class FriendViewHolder extends RecyclerView.ViewHolder {
        TextView name;
        ImageView avatar;

        public FriendViewHolder(View itemView) {
            super(itemView);
            name = itemView.findViewById(R.id.friend_name);
            avatar = itemView.findViewById(R.id.friend_avatar);
        }
    }

    @NonNull
    @Override
    public FriendViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.friend_item, parent, false);
        return new FriendViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull FriendViewHolder holder, int position) {
        holder.avatar.setImageResource(friendList.get(position).getAvatar());
        holder.name.setText(friendList.get(position).getName());
    }

    @Override
    public int getItemCount() {
        return friendList.size();
    }
}
